package com.lin.bank.controller;

import com.lin.bank.config.reponse.Result;
import com.lin.bank.service.AccountService;
import com.lin.bank.vo.AccountVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * 帐户控制器
 *
 * @author Li
 * @date 2022/04/21
 */
@Api(tags = "账户管理")
@RestController
public class AccountController {

    @Resource
    private AccountService accountService;

    @ApiOperation(value = "登录")
    @GetMapping("/login")
    public Result login(String cardNo,String password){
        AccountVO accountVO = new AccountVO(cardNo, password);
        AccountVO login = accountService.login(accountVO);
        return Result.ok().data("token",login);
    }

    @ApiOperation(value = "查询余额")
    @GetMapping("/getBalance")
    public Result getBalance(String cardNo){
        Double balance = accountService.getBalance(cardNo);
        return Result.ok().data("balance",String.valueOf(balance));
    }

    @ApiOperation(value = "修改密码")
    @GetMapping("/updatePassword")
    public Result updatePassword(@RequestParam(name = "cardNo") String cardNo,
                                 @RequestParam(name = "password") String password,
                                 @RequestParam(name = "newPwd") String newPwd){
        int i = accountService.updatePassword(cardNo, password, newPwd);
        return Result.ok().data("updatePassword",i);
    }

    @ApiOperation(value = "转账")
    @GetMapping("/TransferMoney")
    public Result TransferMoney(String cardNo,String cardNo2,Double balance){
        //转账
        int i = accountService.TransferMoney(cardNo, cardNo2, balance);
        return Result.ok().data("TransferMoney",i);
    }

}
